
#ifndef __NETWORK_DB_H
#define __NETWORK_DB_H

#include <apr_network_io.h>
#include "../aprtools/APRTable.h"
#include "SQLiteDB.h"

#define VET_MACHINES

/** Network database containing an understanding of the topology of
 * the network. */
class NetworkDB : public SQLiteDB
{
   public:
      NetworkDB(const char *filename, int persists) : SQLiteDB(filename, persists) { createTablesIfNecessary(); }
      ~NetworkDB();
      void createTablesIfNecessary();
      int addHost(const char *hostname, int portno,
         const char *hostfingerprint, const char *clustername);
      int addCluster(const char *clustername, const char *writedir);
      int addAlias(const char *alias, const char *hostname);
      int addUserCredentials(const char *userid, const char *sshhostname, const char *sshusername, const char *sshkeyname);
      void getAllHostsAccessibleToUserID(const char *userid, std::vector<char *> *allaccessiblehosts, std::vector<int> *allaccessibleports);
      //char *getKeyName(const char *userid, const char *hostname);
      char *getSSHUsername(const char *userid, const char *hostname);
      char *getKeyNameNeededForHostLogin(const char *userid, const char *hostname);
      int updateHostLoginToUseNewKey(const char *userid, const char *hostname, const char *newkeyname);
      int knownHost(const char *hostname);
   protected:
      /** Names of the fields in the 'hosts' table. */
      static const char *table_hosts_fields_names[];
      /** Types of the fields in the 'hosts' table. */
      static const char *table_hosts_fields_types[];
      /** Names of the fields in the 'nodes' table. */
      static const char *table_nodes_fields_names[];
      /** Types of the fields in the 'nodes' table. */
      static const char *table_nodes_fields_types[];
      /** Names of the fields in the 'alias' table. */
      static const char *table_alias_fields_names[];
      /** Types of the fields in the 'alias' table. */
      static const char *table_alias_fields_types[];
      /** Names of the fields in the 'clusters' table. */
      static const char *table_clusters_fields_names[];
      /** Types of the fields in the 'clusters' table. */
      static const char *table_clusters_fields_types[];
      /** Names of the fields in any user credentials table. */
      static const char *table_special_user_credentials_fields_names[];
      /** Types of the fields in any user credentials table. */
      static const char *table_special_user_credentials_fields_types[];
};

#endif
